<?php 
/**
 * TomatoCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@tomatocms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: list.phtml 4684 2010-08-16 08:44:14Z huuphuoc $
 * @since		2.0.2
 */
?>
<?php 
$this->headTitle($this->translator('menu_list_page_title'));

$this->headLink()
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.core.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.resizable.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.dialog.css')
	->appendStylesheet($this->APP_STATIC_SERVER . '/js/jquery.ui/themes/base/ui.theme.css');

$this->headScript()
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.core.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.draggable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.resizable.js')
	->appendFile($this->APP_STATIC_SERVER . '/js/jquery.ui/ui.dialog.js');
?>

<div class="grid_12 t_a_ui_breadcrumb">
	<span><?php echo $this->translator('menu_list_breadcrumb'); ?></span>
</div>

<div class="grid_12 t_a_bottom">
	<div class="grid_9 alpha">
		<?php if ($this->numMenus == 0) : ?>
		<?php echo $this->translator('menu_list_not_found'); ?>
		<?php else : ?>
		<?php echo $this->translator('menu_list_guide'); ?>
		<?php endif; ?>
	</div>
	
	<div class="grid_3 omega">
		<div class="t_a_right">	
			<a href="<?php echo $this->url(array(), 'menu_menu_build'); ?>" class="t_a_ui_button_link"><span><?php echo $this->translator('menu_build_breadcrumb'); ?></span></a>
		</div>
	</div>
</div>

<!-- List of menus -->
<?php if ($this->numMenus == 0) : ?>
<div class="grid_12 t_a_bottom">
	<?php 
	/**
	 * Show language switcher
	 * @since 2.0.8
	 */
	?>
	<?php echo $this->languageSwitcher('flag', str_repeat('&nbsp;', 2)); ?>
</div>	
<?php else : ?>
	<div class="grid_12 t_a_ui_data_list_header">
		<div class="grid_2 alpha">
			<div><?php echo $this->translator('menu_name'); ?></div>
		</div>
		
		<div class="grid_4"><?php echo $this->translator('menu_description'); ?></div>
		
		<div class="grid_2"><?php echo $this->translator('menu_created_date'); ?></div>
                <div class="grid_2 alpha"><?php echo $this->translator('menu_login'); ?></div>
		
		<!--<div class="grid_2"><?php echo $this->languageSwitcher('flag', str_repeat('&nbsp', 2)); ?></div>-->
		
		<div class="grid_1 omega"><?php echo $this->translator('menu_id'); ?></div>
	</div>

	<div class="grid_12">
		<?php foreach ($this->menus as $menu) : ?>
		<div id="menuRow_<?php echo $menu->menu_id; ?>" class="clearfix t_a_ui_data_list_content">
			<div class="grid_2 alpha">
				<div><?php echo $menu->name; ?></div>
				
				<div class="t_a_top t_a_ui_helper_action">
					<?php if ($this->allow('edit')) : ?>
					<a href="<?php echo $this->url(array('menu_id' => $menu->menu_id), 'menu_menu_edit'); ?>"><?php echo $this->translator('menu_list_action_edit'); ?></a> |
					<?php endif; ?>
					
					<?php if ($this->allow('delete')) : ?> 
					<a class="deleteAction" rel="<?php echo $menu->menu_id; ?>" href="javascript: void(0);"><?php echo $this->translator('menu_list_action_delete'); ?></a>
					<?php endif; ?>
				</div>
			</div>
			
			<div class="grid_4">
				<?php if ($menu->description) : ?><?php echo $menu->description; ?><?php else : ?>&nbsp;<?php endif; ?>
			</div>
			
			<div class="grid_2"><?php echo $menu->created_date; ?></div>
			<div class="grid_2 alpha"><?php if ($menu->login) echo $this->translate('yes'); else echo $this->translate('no'); ?></div>
			<?php 
			/**
			 * @since 2.0.8
			 */
			?>
                        <!--
			<div class="grid_2">
			<?php if (($translations = $this->translationItems($menu)) != null) : ?>
				<?php foreach ($translations as $language => $translation) : ?>
					<?php if ($translation == null && $language != $menu->language) : ?>
						<?php if (isset($translations[$this->APP_DEFAULT_LANG])) : ?>
						<a class="t_a_ui_helper_action_add" href="<?php echo $this->url(array('source_id' => $translations[$this->APP_DEFAULT_LANG]->menu_id), 'menu_menu_build_localization'); ?>/<?php echo $language; ?>/">&nbsp;</a>
						<?php else : ?>
						<a class="t_a_ui_helper_action_add" href="<?php echo $this->url(array(), 'menu_menu_build'); ?>/<?php echo $language; ?>/">&nbsp;</a>
						<?php endif; ?>
				
					<?php elseif (($translation == null && $language == $menu->language) || ($translation != null && $translation->menu_id == $menu->menu_id)) : ?>
					<a class="t_a_ui_helper_action_edit" href="<?php echo $this->url(array('menu_id' => $menu->menu_id), 'menu_menu_edit'); ?>/<?php echo $language; ?>/">&nbsp;</a>
					
					<?php elseif ($translation != null && $translation->menu_id != $menu->menu_id) : ?>
					<a class="t_a_ui_helper_action_edit" href="<?php echo $this->url(array('menu_id' => $translation->menu_id), 'menu_menu_edit'); ?>/<?php echo $language; ?>/">&nbsp;</a>
					<?php endif; ?>
				<?php endforeach; ?>
			<?php else : ?>
			&nbsp;
			<?php endif; ?>
			</div>
			-->
			<div class="grid_1 omega"><?php echo $menu->menu_id; ?></div>
		</div>
		<?php endforeach; ?>
	</div>
	
	<div class="grid_12 t_a_bottom t_a_ui_paginator">
		<?php echo $this->paginator()->slide($this->paginator, $this->paginatorOptions); ?>
	</div>
<?php endif; ?>

<div id="messageDialog"></div>

<div id="confirmDialog"></div>

<script type="text/javascript">
$(document).ready(function() {
	<?php if ($this->allow('delete')) : ?>
	$('a.deleteAction').click(function() {
		var self = this;
		$('#confirmDialog').html('<?php echo addslashes($this->translator('menu_list_action_delete_confirm')); ?>')
			.dialog({
				title: '<?php echo addslashes($this->translator('common_dialog_confirm')); ?>',
				dialogClass: 't_a_ui_dialog',
				modal: true,
				closeOnEscape: false,
				resizable: false,
				open: function(event, ui) {
					$('.ui-dialog-titlebar-close').hide();
					$(this).parent().find('.ui-dialog-buttonpane button').wrapInner('<span/>');
				},
				buttons: {
					'<?php echo addslashes($this->translator('common_dialog_confirm_no')); ?>': function() {
						$(this).dialog('destroy');
					},
					'<?php echo addslashes($this->translator('common_dialog_confirm_yes')); ?>': function() {
						$(this).dialog('destroy');
						$(self).html('').addClass('t_a_ui_helper_loading');
						var id = $(self).attr('rel');
						$.ajaxq('menu', {
							type: 'POST',
							url: "<?php echo $this->url(array(), 'menu_menu_delete'); ?>",
							data: { id: id },
							success: function(response) {
								if ('RESULT_OK' == response) {
									$('#menuRow_' + id).fadeOut('slow');
								}
							}
						});
					}
				}
			});
	});
	<?php endif; ?>
});
</script>